﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using SimpleInjector;
using UITLibraryManagement.Repository;
using UITLibraryManagement.ViewModel;
using UITLibraryManagement.View;
using System.Threading;

namespace UITLibraryManagement
{
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            //Create a custom principal with an anonymous identity at startup
            CustomPrincipal customPrincipal = new CustomPrincipal();
            AppDomain.CurrentDomain.SetThreadPrincipal(customPrincipal);

            
            Bootstrap();

            base.OnStartup(e);
        }

        private void Application_Startup(object sender, StartupEventArgs e)
        {

            //Show the login view
            AuthenticationViewModel viewModel = new AuthenticationViewModel(new AuthenticationService());
            IView loginWindow = new LoginWindow();
            loginWindow.ViewModel = viewModel;
            loginWindow.Show();


            //MainWindow wnd = new MainWindow();
            //wnd.Show();

            //demosAPI wndDemos = new demosAPI();
            //wndDemos.Show();

            //ThemDocGia wnd = new ThemDocGia();
            //QuanLyBienMuc wnd = new QuanLyBienMuc();
            //QuanLyMuonTra wnd = new QuanLyMuonTra();
            //Menu wnd = new Menu();
            //wnd.Show();

            
            
            
        }

        private static void Bootstrap()
        {
            //Create the container as usual
            var container = new Container();

            //Register your types, for instance:
            container.Register<IDauSachRepository, DauSachRepository>();
            container.Register<IDocGiaRepository, DocGiaRepository>();



            //Optionally verify the container
            container.Verify();

            //Store the container for use by the application
            App.container = container;
        }



        #region Injector methods
        /*
         * @Helpers method
         */
        public static TService GetInstance<TService>() where TService : class
        {
            return container.GetInstance<TService>();
        }

        /*
         * @Dependency Injection container
         */
        #endregion

        #region Members
        private static Container container;
        #endregion

    }
}
/*
*@Tham khảo Simple Injector
 *http://simpleinjector.codeplex.com/wikipage?title=WPF%20Integration&referringTitle=Integration%20Guide
*/